package com.hencoder.animate;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import org.msgpack.core.MessageBufferPacker;
import org.msgpack.core.MessageFormat;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageUnpacker;

import org.msgpack.value.ValueType;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import javax.xml.transform.Templates;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "Animation";
    private ImageView textView;
    private ValueType valueType;

    static class MyHandler extends Handler{
        private  final WeakReference<MainActivity> mainActivityWeakReference;
        public MyHandler(MainActivity mainActivity) {
            mainActivityWeakReference = new WeakReference<>(mainActivity);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (mainActivityWeakReference.get() != null){
                Log.i(TAG, "handleMessage: 5分钟到");
            }
        }
    }


    /**
     *静态的匿名内部类不会持有外部类的引用
     */
    private static final Runnable runnable = new Runnable() {
        @Override
        public void run() {

        }
    };
     MyHandler myHandler = new MyHandler(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.view);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick:12 ");
            }
        });
        textView.animate().translationX(100).translationY(200).setStartDelay(2000).alpha(0).scaleX(0.5f)
        .rotation(180).setInterpolator(new DecelerateInterpolator()).setDuration(2000).start();
        myHandler.postDelayed(runnable,1000*60*5);
        MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
        try {
            packer
                    .packInt(1)
                    .packString("leo");
            // pack arrays
            int[] arr = new int[] {3, 5, 1, 0, -1, 255};
            packer.packArrayHeader(arr.length);
            for (int v : arr) {
                packer.packInt(v);
            }
            // pack map (key -> value) elements
            packer.packMapHeader(2); // the number of (key, value) pairs
            // Put "apple" -> 1
            packer.packString("apple");
            packer.packInt(1);
            // Put "banana" -> 2
            packer.packString("banana");
            packer.packInt(2);

            // pack binary data
            byte[] ba = new byte[] {1, 2, 3, 4};
            packer.packBinaryHeader(ba.length);
            packer.writePayload(ba);

            packer.close();
            MessageUnpacker messageUnpacker = MessagePack.newDefaultUnpacker(packer.toByteArray());
            while (messageUnpacker.hasNext()){
                MessageFormat messageFormat = messageUnpacker.getNextFormat();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }



    }
}
